<?php if(isset($this->tipMsg) && !empty($this->tipMsg)): ?>
    <div id="login_fail" style="" class="message_error"><?= $this->tipMsg ?></div>
<?php else: ?>
    <div id="login_fail" style="display:none;" class="message_error"></div>
<?php endif; ?>

<div class="clear"></div>
<form class="login" id="form_login" action="<?= $this->L('user', 'login') ?>" method="post">
    <div>
        <label for="email_username">邮箱：</label>
        <div class="clear"></div>
        <?= $this->formLogin->email_username->renderViewHelper();?>
        <?= $this->formLogin->email_username->renderErrors() ?>
    </div>

    <div>
        <label for="password">密码：</label>
        <div class="clear"></div>
        <?= $this->formLogin->password->renderViewHelper(); ?>
        <?= $this->formLogin->password->renderErrors() ?>
    </div>

    <div>
        <div class="clear"></div>
        <?= $this->formLogin->remember_me->renderViewHelper(); ?>
        <label for="remember_me" style="font-size:12px; color:#5F5F5F; display:inline-block; width:auto;">记住我？</label>
    </div>

    <div>
        <input id="login_button" type="submit" name="login" value="Login" style="width:200px;"/>
    </div>
</form>



<script type="text/javascript">
$().ready(function() {
	$('#form_login').ajaxForm({
        beforeSubmit: function (arr, form, options) {
            if($('#email_username').val().length == 0){
                $("#email_username").focus();
                $('#login_fail').html("请输入你的邮箱");
                $('#login_fail').show();
                return false;
            }
            if($('#password').val().length == 0){
                $('#password').focus();
                $('#login_fail').html("请输入你的密码");
                $('#login_fail').show();
                return false;
            }
            if($('#password').val().length < 5 || $('#password').val().length > 32 ){
                $('#password').focus();
                $('#login_fail').html( "对不起，你的邮箱和密码有错误，请重新输入尝试。");
                $('#login_fail').show();
                return false;
            }
            return true;
        },
        success: function (reply) {
            if (reply.error == true) {
                $('#login_fail').html( "对不起，你的邮箱和密码有错误，请重新输入尝试。");
    		    $('#login_fail').show();
                return;
            }
            if (reply.html) {
                location.href = reply.html;
            }
            location.href ="<?= $this->L('index', 'index'); ?>";
        }
    });

    // do some focus
    if ($('#email_username').val() != '') {
        $("#password").focus();
    } else {
        $("#email_username").focus();
    }
});
</script>
